//
//  LabelCell.m
//  UI12 Cell自适应高度
//
//  Created by 郑一楠 on 15/9/1.
//  Copyright (c) 2015年 Riven. All rights reserved.
//

#import "LabelCell.h"

@interface LabelCell ()

@property (nonatomic, retain) UILabel *titleLabel;

@end


@implementation LabelCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //查看此时的高度
        //NSLog(@"%s, %d, %f", __FUNCTION__, __LINE__, self.contentView.frame.size.height);
        self.titleLabel = [[UILabel alloc] init];
        self.titleLabel.backgroundColor = [UIColor colorWithRed:0.12 green:0.55 blue:0.19 alpha:1];
        [self.contentView addSubview:self.titleLabel];
        
        //显示行数
        self.titleLabel.numberOfLines = 0;
        
        [self.titleLabel sizeThatFits:CGSizeMake(375, 0)];
        
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    //查看此时的高度
    //NSLog(@"%s, %d, %f", __FUNCTION__, __LINE__, self.contentView.frame.size.height);
    self.titleLabel.frame = self.contentView.frame;
}
/*
- (void)setModel:(Model *)model {
//    if (_model != model) {
//        [_model release];
//        _model = [model retain];
//    }
    self.titleLabel.text = model.title;
}
*/
#pragma mark - 封装自适应cell高度代码
+ (CGFloat)heightForCellWithText:(NSString *)text {
    CGFloat width = [UIScreen mainScreen].bounds.size.width;
    CGRect rect = [text boundingRectWithSize:CGSizeMake(width, 0)
                                     options:NSStringDrawingUsesLineFragmentOrigin
                                  attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17]}
                                     context:nil];
    
    return rect.size.height + 1;
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
